package com.aididi.java8;

import java.util.ArrayList;
import java.util.function.Predicate;

/**
 * @Auther: zx.xu
 * @Description:    判断型接口。
 */
public class PredicateDemo {

    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student("jack",22));
        list.add(new Student("lisa",16));
        list.add(new Student("mos",32));

        //打印作家中年龄小于18并且姓名长度大于1的作家
        list.stream().
                filter(((Predicate<Student>) author -> author.getAge() < 18).and(author -> author.getName().length() > 1))
                .forEach(author -> System.out.println(author.getName() + ": " + author.getAge()));

        //打印年龄大于17或者小于15的作家。
        list.stream()
                .filter(((Predicate<Student>) author -> author.getAge() > 17).or(
                        author -> author.getAge() < 15)).forEach(System.out::println);
        System.out.println("---------");
        //打印名字不叫mos的作家。
        list.stream()
                .filter(((Predicate<Student>) author -> author.getName().equals("mos")).negate()).forEach(System.out::println);


    }

}



